<?php
	error_reporting(0);
    require_once 'data/handler.php';
    /*$session = new SessionControl();
    if(!$session->Check()){
        //unset($_SESSION['allow']);
        unset($_SESSION['fprint']);
        unset($_SESSION['salt_']);
    }*/
    session_start();
    if(!isset($_SESSION["isLoggedIn"]) || !($_SESSION["isLoggedIn"] === true)){
        session_unset();
        session_destroy();
        header('location: index.php');
    }
    if(isset($_POST['addalbumsubmit'])){
        $keys = array_keys($_POST);
        for($i = 0; $i < 6; $i++) {
            $album[$keys[$i]] = $_POST[$keys[$i]];
        }
        for($i = 6,$j=0; $i < count($_POST)-1; $i+=5,$j++){
            $songs[$j][$keys[$i]] = $_POST[$keys[$i]];
            $songs[$j][$keys[$i+1]] = $_POST[$keys[$i+1]];
            $songs[$j][$keys[$i+2]] = $_POST[$keys[$i+2]];
            $songs[$j][$keys[$i+3]] = $_POST[$keys[$i+3]];
            $songs[$j][$keys[$i+4]] = $_POST[$keys[$i+4]];
        }
        addAlbum($album,$songs);
    }
    else if(isset($_POST['editalbumsubmit'])){
        $keys = array_keys($_POST);
        for($i = 0; $i < 7; $i++){
            $album[$keys[$i]] = $_POST[$keys[$i]];
        }
        editAlbum($album);
    }
    else if(isset($_POST['delalbumsubmit'])){
        delAlbum($_POST);
    }
    else if(isset($_POST['delcustsubmit'])){
        delAccount($_POST);
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Musique Basse</title>
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
        <link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/jquery.validate.js"></script>
        <script type="text/javascript" src="js/adminhandler.js"></script>
    </head>
    <body>
        <div id="main" class="page">
            <header>
                <h1><img src="buttons/logo.png"/></h1>
                <h6>A music store for all kinds of music listeners</h6>
                <nav>
                    <a href="index.php"><img src="buttons/home.png"/></a>
                    <a href="products.php"><img src="buttons/products.png"/></a>
                    <!--accessible or shown only to logged in users-->
                    <?php //var_dump($_SESSION);
                        if(!isset($_SESSION["isLoggedIn"]) || !($_SESSION["isLoggedIn"] === true))
                            echo '<a href="login.php" class="fltright"><img src="buttons/login.png"/></a>';
                        else{
                            echo '<a href="account.php"><img src="buttons/account.png"/></a>';
                            if(isAdmin($_SESSION["uname"]))
                                echo ' <a href="admin.php"><img src="buttons/admincp.png"/></a>';
							echo '<a href="cart.php"><img src="buttons/Cart.png"/></a>';
                            echo '<a href="logout.php" class="fltright"><img src="buttons/logout.png"/></a>';
                        }
                    ?>
                </nav>
            </header>
            
            <div id="content">
                <div class="admin">
                    <button id="addalbum" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">Add Album</h4>
                    <div id="addalbumdetails" class="displaynone">
                        <form id="addalbumform" name="addalbumform" method="post" action="">
                            <ul>
                                <li>
                                    <label for="albumnm">Album Title:</label>
                                    <input type="text" id="albumnm" name="albumnm" />
                                </li>
                                <li>
                                    <label for="albumartist">Artist:</label>
                                    <input type="text" id="albumartist" name="albumartist" />
                                </li>
                                <li>
                                    <label for="albumart">Album Art:</label>
                                    <input type="file" id="albumart" name="albumart" />
                                </li>
                                <li>
                                    <label for="albumgenre">Genre:</label>
                                    <input type="text" id="albumgenre" name="albumgenre" />
                                </li>
                                <li>
                                    <label for="albumdesc">Description:</label>
                                    <textarea id="albumdesc" name="albumdesc"></textarea>
                                </li>
                                <li>
                                    <label for="albumyr">Year:</label>
                                    <input type="text" id="albumyr" name="albumyr" />
                                </li>
                                <li>
                                    <h5>Songs:</h5>
                                    <ol>
                                        <li id="track1" class="clonedsong">
                                            <ul>
                                                <li>
                                                    <label>Title</label><input type="text" id="song1" name="song1" />
                                                </li>
                                                <li>
                                                    <label>Duration</label><input type="text" id="dur1" name="dur1" />
                                                </li>
                                                <li>
                                                    <label>File</label><input type="file" id="file1" name="file1" />
                                                </li>
                                                <li>
                                                    <label>Preview File</label><input type="file" id="prev1" name="prev1" />
                                                </li>
                                                <li>
                                                    <label>Price</label><input type="text" id="price1" name="price1" />
                                                </li>
                                            </ul>
                                        </li>
                                    </ol>
                                    <input type="button" id="addsong" name="addsong" value="Add another song" />
                                </li>
                                <li><input type="submit" id="addalbumsubmit" name="addalbumsubmit" value="Add Album" /></li>
                            </ul>
                        </form>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="editalbum" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">Edit Album</h4>
                    <div id="editalbumdetails" class="displaynone">
                        <form id="search4edit" name="search4edit" method="post" action="">
                            <label for="album2edit" style="width:auto">Album Title</label>
                            <input type="text" id="album2edit" name="album2edit" />
                            <input type="submit" id="search4editbutton" name="search4editbutton" value="Search"/>
                        </form>
                        <div id="search4editres"></div>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="delalbum" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">Delete Album</h4>
                    <div id="delalbumdetails" class="displaynone">
                        <form id="search4del" name="search4del" method="post" action="">
                            <label for="album2del" style="width:auto">Album Title</label>
                            <input type="text" id="album2del" name="album2del" />
                            <input type="submit" id="search4delbutton" name="search4delbutton" value="Search"/>
                        </form>
                        <div id="search4delres"></div>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="viewalbum" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">View Album</h4>
                    <div id="viewalbumdetails" class="displaynone">
                        <form id="search4view" name="search4view" method="post" action="">
                            <label for="album2view" style="width:auto">Album Title</label>
                            <input type="text" id="album2view" name="album2view" />
                            <input type="submit" id="search4viewbutton" name="search4viewbutton" value="Search"/>
                        </form>
                        <div id="search4viewres"></div>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="viewcustomer" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">View Accounts</h4>
                    <div id="viewcustomerdetails" class="displaynone">
                        <?php
                            getAccounts();
                        ?>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="delcustomer" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">Delete Customer</h4>
                    <div id="delcustomerdetails" class="displaynone">
                        <form id="search4delcust" name="search4delcust" method="post" action="">
                            <label for="cust2del" style="width:auto">Account e-mail</label>
                            <input type="text" id="cust2del" name="cust2del" />
                            <input type="submit" id="search4delcustbutton" name="search4delcustbutton" value="Search"/>
                        </form>
                        <div id="search4delcustres"></div>
                    </div>
                </div>
                
                <div class="admin">
                    <button id="vieworders" class="adminbutton">&#x25B6;</button>
                    <h4 class="inlinedisplay">View Orders</h4>
                    <div id="viewordersdetails" class="displaynone">
                        asdadasddas
                    </div>
                </div>
            </div>
            
            <div class="clear"></div>
            
            <footer>
                <p>Copyright &copy; 2012 KENNICS. All rights reserved.</p>
                <p>Design by Werdnazner</p>
            </footer>
        </div>
    </body>
</html>